package frontend.container.taskPanel;

import java.awt.Color;
import java.awt.Cursor;
import java.awt.Font;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JLabel;

import frontend.base.BaseLabel;
import frontend.base.BasicPanel;
import frontend.interf.IAddTabPanel;

public class TaskLabel extends BaseLabel implements MouseListener{

	/**
	 * 
	 */
	private static final long serialVersionUID = -2115418861769450092L;

	final Font defaultFont = this.getFont();
	final Color defaultForeColor = this.getForeground();
	final Font mouseOnFont = new Font("Dialog", Font.ITALIC, defaultFont.getSize());
	final Color mouseOnColor = Color.red;
	private IAddTabPanel parentClass;
	
	/**
	 * this is the unique task ID to identify to other task label if need tabpannel method
	 */
	private String taskId = "";

	/**
	 * this is the class that for class for name method.
	 */
	private String className = "";
	
	public String getTaskId() {
		return taskId;
	}

	public void setTaskId(String taskId) {
		this.taskId = taskId;
	}

	public String getClassName() {
		return className;
	}

	public TaskLabel(String text) {
		super(text);
		this.addMouseListener(this);
	}
	public void setClassName(String className) {
		this.className = className;
	}

	@Override
	public void mouseClicked(MouseEvent e) {
		BasicPanel panel = null;
		try {
			panel = (BasicPanel) Class.forName(className).newInstance();
			panel.setId(taskId);
			panel.setTitle(getText());
		} catch (InstantiationException e1) {
			e1.printStackTrace();
		} catch (IllegalAccessException e1) {
			e1.printStackTrace();
		} catch (ClassNotFoundException e1) {
//			JXErrorPane.showDialog(parent, new ErrorInfo(
//					"Application Error", "2", null, "3", e1,
//					Level.SEVERE, null));
			e1.printStackTrace();
		}
	if(panel != null) {
		parentClass.addTabPanel(panel);
	}
		
	}

	@Override
	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseEntered(MouseEvent e) {
		JLabel lbl = (JLabel)e.getSource();
		lbl.setCursor(new Cursor(Cursor.HAND_CURSOR));
		lbl.setFont( mouseOnFont);
	}

	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub
		JLabel lbl = (JLabel)e.getSource();
		lbl.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
		lbl.setFont(defaultFont);
	}

	public IAddTabPanel getParentClass() {
		return parentClass;
	}

	public void setParentClass(IAddTabPanel parentClass) {
		this.parentClass = parentClass;
	}
}
